<?php


@session_start();
require_once 'shared-functions.php';
require_once 'session.php';
require('fpdf.php');


$link = connect_db();
//$query = "SELECT `StudentID`, `CourseInstanceID`, `ItemID`, `Points`, `Comment`, `FirstName`, `MiddleName`, `LastName` FROM `StudentGrade` INNER JOIN `User` ON `User`.`UserId`=`StudentGrade`.`StudentID` WHERE `CourseInstanceID`='" . $_POST['CourseInstance'] . "' AND `ItemID`='" . $_POST['ItemID'] . "'";
$query = "SELECT `StudentID`, `CourseInstanceID`, `ItemID`, `Points`, `Comment`, `FirstName`, `MiddleName`, `LastName` FROM `StudentGrade` INNER JOIN `User` ON `User`.`UserId`=`StudentGrade`.`StudentID` WHERE `CourseInstanceID`='" . $_POST['CourseInstance'] . "'";
$grades = mysql_query($query, $link);
if(!$grades) {
	echo "Oops...something went wrong. Please contact support.";
	exit();
}


$pdf = new FPDF();
$pdf->AddPage();



$pdf->SetFont('Arial', 'B', 24);
$pdf->SetTextColor(255, 255, 255);
$pdf->SetFillColor(48, 68, 98);
$pdf->SetDrawColor(48, 68, 98);
$pdf->Cell(40, 10, 'Grades', 1, 0, 'L', true);


$pdf->Ln();
$pdf->Ln();


$pdf->SetFont('Arial', '', 12);
$pdf->SetTextColor(48, 68, 98);
$pdf->Cell(50, 5, 'Name', 1, 1, 'L');

$i = 2;

while($tblrow = mysql_fetch_array($grades, MYSQL_BOTH)) {
	
	
	$pdf->Cell(40, 10, $tblrow['LastName'] . ', ' . $tblrow['FirstName'] . ' ' . $tblrow['MiddleName'], 0, $i, 'L');
	$pdf->Cell(40, 10, $tblrow['Points'], 0, $i, 'L');
	
	$i++;
	
}




// Draw PDF
$pdf->Output();



?>